package com.mingteng.mobile_feedback;

import com.mingteng.mobile_feedback.respository.JdbcRepository;
import com.mingteng.mobile_feedback.respository.impl.JdbcRepositoryImpl;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.jdbc.DataSourceBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.jdbc.core.JdbcTemplate;

import javax.sql.DataSource;

@SpringBootApplication
public class MobileFeedbackApplication {

    public static void main(String[] args) {
        SpringApplication.run(MobileFeedbackApplication.class, args);
    }

    @Bean(name = "dataSource")
    @ConfigurationProperties(prefix = "spring.datasource")
    public DataSource dataSource(){
        return DataSourceBuilder.create().build();
    }

    @Bean
    public JdbcTemplate getJdbcTemplate(){
        JdbcTemplate jdbcTemplate = new JdbcTemplate();
        jdbcTemplate.setDataSource(dataSource());
        return jdbcTemplate;
    }

    @Bean
    public JdbcRepository GetJdbcRepository(){
        return new JdbcRepositoryImpl();
    }
}
